package com.szp.drug.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 通用返回类
 * @author SuZePing
 * @create 2021-01-10 17:42
 * @E-mail suzeping10@126.com
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultEntity<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	private static final String SUCCESS = "success";

	private static final String FAILED = "failed";

	// 成功或失败标志
	private String code;

	// 信息
	private String msg;

	// 数据
	private T data;

	/**
	 * 请求成功不需要数据
	 * @return
	 */
	public static <E> ResultEntity<E> success() {
		return new ResultEntity<E>(SUCCESS,null,null);
	}

	/**
	 * 请求成功需要数据
	 * @return
	 */
	public static <E> ResultEntity<E> success(E data) {
		return new ResultEntity<E>(SUCCESS,null,data);
	}

	/**
	 * 请求失败返回错误信息
	 * @return
	 */
	public static <E> ResultEntity<E> error(String msg) {
		return new ResultEntity<E>(FAILED,msg,null);
	}
}
